import { getListApi } from "@/api/user";
import { ListUserParam } from "@/api/user/UserModel";

import { nextTick, onMounted, ref } from "vue";
import { reactive } from "vue";



export default function useUserTable() {
    
    const tableHeight = ref(0)

    
    const listParam = reactive<ListUserParam>({
 
 
        customerAttributes: '',
      
 
    })
    
    const tableList = ref([])
    
    const getList = async () => {
        let res = await getListApi(listParam);
        console.log(res)
        if (res && res.code == 200) {
            tableList.value = res.data;
        }
    }

    
    const searchBtn = () => {
        getList()
    }
    
    const resetBtn = () => {
        listParam.customerAttributes = '';
        getList()
    }

    onMounted(() => {
        getList()
        
        nextTick(() => {
            tableHeight.value = window.innerHeight - 220
        })
    })
    return {
        listParam,
        searchBtn,
        resetBtn,
        getList,
        tableList,
        tableHeight
    }
}
